package Main.ThreadTest;

import java.util.Scanner;

/**
 * PACKAGE_NAME: Main.ThreadTest
 * Description:
 */
public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new ThreadTest();
        thread.start();

        String str = "1、 stop 2、start";
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println(str);
            switch (scanner.nextInt()) {
                case 1:
                    thread.interrupt();
                    break;
                case 2:
                    thread.start();
                    break;
            }
        }
    }
}

class ThreadTest extends Thread {

    @Override
    public void run() {
        System.out.println("开始！");
        int i = 0;
        while (true) {
            if (this.interrupted()) { // 如果插嘴结束
                System.out.println(++i);
            }
        }
    }
}
